package com.sgb.kjwl.view.ui.adapter.self.publish;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter2;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class StationServierAdapter extends BaseRecycleAdapter2<String> {

    private TextView delete_tv;
    boolean isEdite;

    public StationServierAdapter(Context context, List<String> datas) {
        super(context, R.layout.item_service_type, datas);
    }

    public void setEdite(boolean edite) {
        isEdite = edite;
        notifyDataSetChanged();
    }

    @Override
    public void convert(ItemViewHolder holder, String entity, int position) {
        holder.setBinding(BR.viewModel, entity);
        EditText tvContent=holder.itemView.findViewById(R.id.et_content);
        delete_tv = holder.itemView.findViewById(R.id.tv_delete);
        if(isEdite){
            delete_tv.setVisibility(View.VISIBLE);
        }else{
            delete_tv.setVisibility(View.GONE);
        }
        tvContent.setText(entity);
        delete_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                removeItem(entity);
            }
        });
        tvContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                getDatas().set(position,tvContent.getText().toString());

            }
        });
    }
}
